package com.howard.webapp.familymanagement.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@DynamicInsert 
@DynamicUpdate //生成的SQL中涉及的字段只包含User类中修改的属性所对应的表字段
@Table(name="T_MENU")
public class Menu {
	@Id
	@Column(name = "ID") 
	@SequenceGenerator(name="MENU_ID_GENERATOR", sequenceName="SEQ_MENU_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="MENU_ID_GENERATOR")
	private Long id;
	
	@Column(name = "P_ID") 
	private Long pId;
	
	@Column(name = "SEQ") 
	private Integer seq;
	
	@Column(name = "NAME") 
	private String text;
	
	@Column(name = "URL") 
	private String url;
	
	@Column(name = "IS_ACTIVE") 
	private String isActive;
	
	@Column(name = "CTR_TIME") 
	private Date crtTime;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getpId() {
		return pId;
	}

	public void setpId(Long pId) {
		this.pId = pId;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIsActive() {
		return isActive;
	}

	public void setIsActive(String isActive) {
		this.isActive = isActive;
	}

	public Date getCrtTime() {
		return crtTime;
	}

	public void setCrtTime(Date crtTime) {
		this.crtTime = crtTime;
	}
	
	//add by Howard
	@Transient
  	private List<Menu> children = null;
	@Transient
  	private String state;
	@Transient
  	private Map<String, String> attributes = new HashMap<String, String>();

  	public List<Menu> getChildren() {
  		return children;
  	}
  	
  	public void addChild(Menu child) {
  		if (children==null){
  			children = new ArrayList<Menu>(0);
  		}
  		children.add(child);
  	}

  	public void setChildren(List<Menu> children) {
  		this.children = children;
  	}
  	
  	public String getState() {
  		if(children != null && children.size() > 0){
  			this.state = "closed";
  		}
  		else{
  			this.state = "open";
  		}
  		return this.state;
  	}

  	public void setState(String state) {
  		this.state = state;
  	}

  	public Map<String, String> getAttributes() {
  		return this.attributes;
  	}

  	public void addAttribute(String key, String value) {
  		this.attributes.put(key, value);
  	}
}
